package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusinessCard;
import com.ruoyi.system.service.IBusinessCardService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电子名片信息表Controller
 * 
 * @author ruoyi
 * @date 2024-06-13
 */
@Controller
@RequestMapping("/system/card")
public class BusinessCardController extends BaseController
{
    private String prefix = "system/card";

    @Autowired
    private IBusinessCardService businessCardService;

    @RequiresPermissions("system:card:view")
    @GetMapping()
    public String card()
    {
        return prefix + "/card";
    }

    /**
     * 查询电子名片信息表列表
     */
    @RequiresPermissions("system:card:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusinessCard businessCard)
    {
        startPage();
        List<BusinessCard> list = businessCardService.selectBusinessCardList(businessCard);
        return getDataTable(list);
    }

    /**
     * 导出电子名片信息表列表
     */
    @RequiresPermissions("system:card:export")
    @Log(title = "电子名片信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusinessCard businessCard)
    {
        List<BusinessCard> list = businessCardService.selectBusinessCardList(businessCard);
        ExcelUtil<BusinessCard> util = new ExcelUtil<BusinessCard>(BusinessCard.class);
        return util.exportExcel(list, "电子名片信息表数据");
    }

    /**
     * 新增电子名片信息表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片信息表
     */
    @RequiresPermissions("system:card:add")
    @Log(title = "电子名片信息表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusinessCard businessCard)
    {
        return toAjax(businessCardService.insertBusinessCard(businessCard));
    }

    /**
     * 修改电子名片信息表
     */
    @RequiresPermissions("system:card:edit")
    @GetMapping("/edit/{bcId}")
    public String edit(@PathVariable("bcId") Long bcId, ModelMap mmap)
    {
        BusinessCard businessCard = businessCardService.selectBusinessCardByBcId(bcId);
        mmap.put("businessCard", businessCard);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片信息表
     */
    @RequiresPermissions("system:card:edit")
    @Log(title = "电子名片信息表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusinessCard businessCard)
    {
        return toAjax(businessCardService.updateBusinessCard(businessCard));
    }

    /**
     * 删除电子名片信息表
     */
    @RequiresPermissions("system:card:remove")
    @Log(title = "电子名片信息表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(businessCardService.deleteBusinessCardByBcIds(ids));
    }
}
